package com.wgtgt.eclipse_project_create;

import cn.hutool.core.io.FileUtil;
import cn.hutool.core.util.StrUtil;

/**
 * Hello world!
 *
 */
public class App {
	public static void main(String[] args) {
		System.out.println("Hello World!");
		String path = "E:\\work2\\work23\\solidwork";
		gen(path);
	}

	private static void gen(String path) {
		path = path.replace("\\", "/");
		String name = StrUtil.subAfter(path, "/", true);
		String contentPrefs = genPrefs();
		String contentProject = genProject(name);
		String pathPrefs = StrUtil.removeSuffix(path, "/") + "/.settings/org.eclipse.core.resources.prefs";
		String pathProject = StrUtil.removeSuffix(path, "/") + "/.project";
		FileUtil.writeUtf8String(contentPrefs, pathPrefs);
		FileUtil.writeUtf8String(contentProject, pathProject);
		System.out.println(pathPrefs);
		System.out.println(pathProject);
	}

	private static String genProject(String name) {
		String nl = "\r\n";
		StringBuilder sb = new StringBuilder();
		sb.append("");
		sb.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		sb.append(nl);
		sb.append("<projectDescription>");
		sb.append(nl);
		sb.append("	<name>");
		sb.append(name);
		sb.append("</name>");
		sb.append(nl);
		sb.append("	<comment></comment>");
		sb.append(nl);
		sb.append("	<projects>");
		sb.append(nl);
		sb.append("	</projects>");
		sb.append(nl);
		sb.append("	<buildSpec>");
		sb.append(nl);
		sb.append("	</buildSpec>");
		sb.append(nl);
		sb.append("	<natures>");
		sb.append(nl);
		sb.append("	</natures>");
		sb.append(nl);
		sb.append("</projectDescription>");
		sb.append(nl);
		return sb.toString();
	}

	private static String genPrefs() {
		String nl = "\r\n";
		StringBuilder sb = new StringBuilder();
		sb.append("eclipse.preferences.version=1");
		sb.append(nl);
		sb.append("encoding/<project>=UTF-8");
		sb.append(nl);
		return sb.toString();
	}
}
